/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ee.asynchronous;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.ejb.AsyncResult;
import javax.ejb.Asynchronous;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.apache.log4j.Logger;

/**
 *
 * @author Gabriel Bran <gbran.u@gmail.com>
 */
@Stateless
@LocalBean
public class TestAsynchronous {
    
    @Inject
    private Logger logger;
    @EJB
    private AsynchronousBean asynchronousBean;
    
    public void pruebaInicioTarea() throws InterruptedException, ExecutionException {
        logger.info("Tarea inicial: hilo => " + Thread.currentThread().getName());
        Future<String> r = asynchronousBean.pruebaTareaAsincrona();
        logger.info("Continuando: hilo => " + Thread.currentThread().getName());
        
        while (!r.isDone()) {
            Thread.sleep(1000L);
        }
        logger.info(r.get());
        
        logger.info("Finalizando tarea inicial: hilo => " + Thread.currentThread().getName());
    }
    
}
